//
//  MainCacheTool.m
//  MilkProject
//
//  Created by 叶子韬韬 on 2017/3/10.
//  Copyright © 2017年 叶子韬韬. All rights reserved.
//

#import "MainCacheTool.h"

@implementation MainCacheTool
+(NSData *)getDataWithDictionary:(NSDictionary *)dictionary {
    NSData *data = [NSJSONSerialization dataWithJSONObject:dictionary options:NSJSONWritingPrettyPrinted error:nil];
    return data;
}
+(NSDictionary *)getDictionaryWithData:(NSData *)data {
    if (!data) {
        return nil;
    }
    NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
    return dict;
}
+(NSData *)getDataWithArray:(NSMutableArray *)array {
    NSData *data = [NSJSONSerialization dataWithJSONObject:array options:NSJSONWritingPrettyPrinted error:nil];
    return data;
}
+(NSMutableArray *)getArrayWithData:(NSData *)data {
    NSMutableArray *array = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
    return array;
}
+(NSString *)getStringWithDictionary:(NSDictionary *)dict{
    NSString *jsonString = nil;
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict
                                                       options:NSJSONWritingPrettyPrinted
                                                         error:&error];
    if (! jsonData) {
        NSLog(@"Got an error: %@", error);
    } else { 
        jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; 
    } 
    return jsonString;
}
@end
